import { IPSAppView } from '../../app/view/ipsapp-view';
import { IPSSpan } from './ipsspan';
import { PSCodeListEditorImpl } from './pscode-list-editor-impl';

export class PSSpanImpl extends PSCodeListEditorImpl implements IPSSpan {
  get caption(): string {
    return this.M.caption;
  }

  get hAlign(): 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFY' {
    return this.M.hAlign || 'LEFT';
  }

  protected linkpsappview: IPSAppView | null = null;

  getLinkPSAppView(): IPSAppView | null {
    if (this.linkpsappview != null) return this.linkpsappview;
    const value = this.M.getLinkPSAppView;
    if (value == null) {
      return null;
    }
    this.linkpsappview = this.getPSModel4('app.view.IPSAppView', value, 'getLinkPSAppView') as IPSAppView;
    return this.linkpsappview;
  }

  get linkPSAppView(): IPSAppView | null {
    return this.getLinkPSAppView();
  }

  getLinkPSAppViewMust(): IPSAppView {
    const value = this.getLinkPSAppView();
    if (value == null) {
      throw new Error('未指定数据链接视图');
    }
    return value;
  }

  get precision(): number {
    return this.M.precision;
  }

  get renderMode(): 'TEXT' | 'HEADING1' | 'HEADING2' | 'HEADING3' | 'HEADING4' | 'HEADING5' | 'HEADING6' | 'PARAGRAPH' {
    return this.M.renderMode;
  }

  get vAlign(): 'TOP' | 'MIDDLE' | 'BOTTOM' {
    return this.M.vAlign || 'MIDDLE';
  }

  get wrapMode(): 'WRAP' | 'NOWRAP' {
    return this.M.wrapMode || 'NOWRAP';
  }

  get editable(): boolean {
    return this.M.editable != null ? this.M.editable : false;
  }

  get enableLinkView(): boolean {
    return this.M.enableLinkView;
  }

  get cls(): string {
    return 'PSSpanImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSTextBase' || cls == 'control.editor.IPSSpan') return true;
    return super.instanceof(cls);
  }
}
